//
//  ViewController.m
//  25-刘叹气分享-下拉放大
//
//  Created by mafeng on 16/8/17.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#define kScreenWidth  [UIScreen mainScreen].bounds.size.width

#define kScreenHeight  [UIScreen mainScreen].bounds.size.height

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) UIView *backViewForTableHeaderView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImageView *barImageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *view = [self createHeaderView];
    _tableView.tableHeaderView = view;
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    self.barImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, kScreenWidth, 64)];
    _barImageView.image = [UIImage imageNamed:@"tts-navbar"];
    [self.navigationController.navigationBar addSubview:_barImageView];
    
}


- (UIView *)createHeaderView {
    self.backViewForTableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, kScreenWidth, 200)];
    self.imageView = [[UIImageView alloc] initWithFrame:self.backViewForTableHeaderView.bounds];
    _imageView.image = [UIImage imageNamed:@"1.jpg"];
    [_backViewForTableHeaderView addSubview:_imageView];
    return _backViewForTableHeaderView;
}


// tableView 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offset_Y = scrollView.contentOffset.y;
    CGFloat alpha = (offset_Y + 64) / 200.0f;
    self.barImageView.alpha = alpha;
    if (offset_Y < -64) {
        CGFloat add_height = -(offset_Y + 64);
        CGFloat scale = (200 + add_height) / 200.0f
        ;
        self.imageView.frame = CGRectMake(-(kScreenWidth * scale - kScreenWidth) / 2.0f , -add_height, kScreenWidth * scale, 200 + add_height);
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
